package cn.csc.module.member.framework.shutdown;

import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * 优雅停机
 * Author: liuchuang
 * Date: 2025/2/3
 * Time: 19:46
 * Declaration: All Rights Reserved !!!
 */
@Slf4j
@Component
public class ShutdownGraceful {

    @Value("${spring.application.name}")
    private String appName;

    @Resource
    private NacosAutoServiceRegistration nacosAutoServiceRegistration;

    @PreDestroy
    public void shutdown() {
        log.info(appName+"准备优雅停止...");
        nacosAutoServiceRegistration.stop();
        log.info(appName+"优雅停止完成");
    }

}
